home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / exampleCode / games / IndiZone / sw / ship_regular.c++ < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-02  |  8.9 KB  |  346 lines

  1. /*
  2.  * Copyright (C) 1994, Silicon Graphics, Inc.
  3.  * All Rights Reserved.
  4.  *
  5.  * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  6.  * the contents of this file may not be disclosed to third parties, copied or
  7.  * duplicated in any form, in whole or in part, without the prior written
  8.  * permission of Silicon Graphics, Inc.
  9.  *
  10.  * RESTRICTED RIGHTS LEGEND:
  11.  * Use, duplication or disclosure by the Government is subject to restrictions
  12.  * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  13.  * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  14.  * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  15.  * rights reserved under the Copyright Laws of the United States.
  16.  */
  17. #include "sw.h"
  18. #include "ship_regular.h"
  19. #include "resources.h"
  20. #include <Inventor/nodes/SoSeparator.h>
  21. #include <Inventor/nodes/SoLightModel.h>
  22. #include <Inventor/nodes/SoMaterial.h>
  23. #include <Inventor/nodes/SoRotation.h>
  24. #include <Inventor/nodes/SoTranslation.h>
  25. #include <Inventor/nodes/SoComplexity.h>
  26. #include <Inventor/nodes/SoCoordinate3.h>
  27. #include <Inventor/nodes/SoCone.h>
  28. #include <Inventor/nodes/SoFaceSet.h>
  29. #include <Inventor/nodes/SoShapeHints.h>
  30.  
  31. static float        shipGeometry[][3] = {
  32.                 // right body front face
  33.                 { -5.0, -8.0, -5.0 },
  34.                 { -10.0, -8.0, -5.0 },
  35.                 { -15.0, -5.0, -5.0 },
  36.                 { -15.0, 5.0, -5.0 },
  37.                 { -10.0, 8.0, -5.0 },
  38.                 { -5.0, 8.0, -5.0 },
  39.                 // right body back face
  40.                 { -5.0, 8.0, 15.0 },
  41.                 { -10.0, 8.0, 15.0 },
  42.                 { -15.0, 5.0, 15.0 },
  43.                 { -15.0, -5.0, 15.0 },
  44.                 { -10.0, -8.0, 15.0 },
  45.                 { -5.0, -8.0, 15.0 },
  46.                 // right body outside face
  47.                 { -15.0, 5.0, -5.0 },
  48.                 { -15.0, -5.0, -5.0 },
  49.                 { -15.0, -5.0, 15.0 },
  50.                 { -15.0, 5.0, 15.0 },
  51.                 // right body outside top face
  52.                 { -10.0, 8.0, -5.0 },
  53.                 { -15.0, 5.0, -5.0 },
  54.                 { -15.0, 5.0, 15.0 },
  55.                 { -10.0, 8.0, 15.0 },
  56.                 // right body outside bottom face
  57.                 { -15.0, -5.0, -5.0 },
  58.                 { -10.0, -8.0, -5.0 },
  59.                 { -10.0, -8.0, 15.0 },
  60.                 { -15.0, -5.0, 15.0 },
  61.                 // right body inside face
  62.                 { -5.0, 8.0, -5.0 },
  63.                 { -5.0, 8.0, 15.0 },
  64.                 { -5.0, -8.0, 15.0 },
  65.                 { -5.0, -8.0, -5.0 },
  66.                 // right body top face
  67.                 { -5.0, 8.0, 15.0 },
  68.                 { -5.0, 8.0, -5.0 },
  69.                 { -10.0, 8.0, -5.0 },
  70.                 { -10.0, 8.0, 15.0 },
  71.                 // right body bottom face
  72.                 { -5.0, -8.0, -5.0 },
  73.                 { -5.0, -8.0, 15.0 },
  74.                 { -10.0, -8.0, 15.0 },
  75.                 { -10.0, -8.0, -5.0 },
  76.  
  77.                 // left body front face
  78.                 { 5.0, 8.0, -5.0 },
  79.                 { 10.0, 8.0, -5.0 },
  80.                 { 15.0, 5.0, -5.0 },
  81.                 { 15.0, -5.0, -5.0 },
  82.                 { 10.0, -8.0, -5.0 },
  83.                 { 5.0, -8.0, -5.0 },
  84.                 // left body back face
  85.                 { 5.0, -8.0, 15.0 },
  86.                 { 10.0, -8.0, 15.0 },
  87.                 { 15.0, -5.0, 15.0 },
  88.                 { 15.0, 5.0, 15.0 },
  89.                 { 10.0, 8.0, 15.0 },
  90.                 { 5.0, 8.0, 15.0 },
  91.                 // left body outside face
  92.                 { 15.0, -5.0, -5.0 },
  93.                 { 15.0, 5.0, -5.0 },
  94.                 { 15.0, 5.0, 15.0 },
  95.                 { 15.0, -5.0, 15.0 },
  96.                 // left body outside top face
  97.                 { 15.0, 5.0, -5.0 },
  98.                 { 10.0, 8.0, -5.0 },
  99.                 { 10.0, 8.0, 15.0 },
  100.                 { 15.0, 5.0, 15.0 },
  101.                 // left body outside bottom face
  102.                 { 10.0, -8.0, -5.0 },
  103.                 { 15.0, -5.0, -5.0 },
  104.                 { 15.0, -5.0, 15.0 },
  105.                 { 10.0, -8.0, 15.0 },
  106.                 // left body inside face
  107.                 { 5.0, -8.0, -5.0 },
  108.                 { 5.0, -8.0, 15.0 },
  109.                 { 5.0, 8.0, 15.0 },
  110.                 { 5.0, 8.0, -5.0 },
  111.                 // left body top face
  112.                 { 5.0, 8.0, -5.0 },
  113.                 { 5.0, 8.0, 15.0 },
  114.                 { 10.0, 8.0, 15.0 },
  115.                 { 10.0, 8.0, -5.0 },
  116.                 // left body bottom face
  117.                 { 5.0, -8.0, 15.0 },
  118.                 { 5.0, -8.0, -5.0 },
  119.                 { 10.0, -8.0, -5.0 },
  120.                 { 10.0, -8.0, 15.0 },
  121.  
  122.                 // core top
  123.                 { 5.0, 2.0, 5.0 },
  124.                 { 5.0, 2.0, -10.0 },
  125.                 { -5.0, 2.0, -10.0 },
  126.                 { -5.0, 2.0, 5.0 },
  127.                 // core rear
  128.                 { 5.0, 2.0, 5.0 },
  129.                 { -5.0, 2.0, 5.0 },
  130.                 { -5.0, -2.0, 5.0 },
  131.                 { 5.0, -2.0, 5.0 },
  132.                 // core bottom
  133.                 { -5.0, -2.0, 5.0 },
  134.                 { -5.0, -2.0, -10.0 },
  135.                 { 5.0, -2.0, -10.0 },
  136.                 { 5.0, -2.0, 5.0 },
  137.                 // core right side
  138.                 { -5.0, 2.0, 5.0 },
  139.                 { -5.0, 2.0, -10.0 },
  140.                 { -5.0, -2.0, -10.0 },
  141.                 { -5.0, -2.0, 5.0 },
  142.                 // core left side
  143.                 { 5.0, 2.0, 5.0 },
  144.                 { 5.0, -2.0, 5.0 },
  145.                 { 5.0, -2.0, -10.0 },
  146.                 { 5.0, 2.0, -10.0 },
  147.  
  148.                 // nose top
  149.                 { 5.0, 2.0, -10.0 },
  150.                 { 0.0, -2.0, -20.0 },
  151.                 { -5.0, 2.0, -10.0 },
  152.                 // nose bottom
  153.                 { 5.0, -2.0, -10.0 },
  154.                 { -5.0, -2.0, -10.0 },
  155.                 { 0.0, -2.0, -20.0 },
  156.                 // nose right side
  157.                 { -5.0, 2.0, -10.0 },
  158.                 { 0.0, -2.0, -20.0 },
  159.                 { -5.0, -2.0, -10.0 },
  160.                 // nose left side
  161.                 { 5.0, 2.0, -10.0 },
  162.                 { 5.0, -2.0, -10.0 },
  163.                 { 0.0, -2.0, -20.0 } };
  164. #define    NUMCOORDS    (sizeof(shipGeometry) / sizeof(float))
  165. static long        shipGeometryEdges[] =
  166.                 { 6, 6, 4, 4, 4, 4, 4, 4,    // right body
  167.                   6, 6, 4, 4, 4, 4, 4, 4,    // left body
  168.                   4, 4, 4, 4, 4,        // core
  169.                   3, 3, 3, 3 };            // nose
  170. #define    NUMEDGES    (sizeof(shipGeometryEdges) / sizeof(long))
  171.  
  172. RegularShip::RegularShip(NetId id, Team t, const char* n) : ShipObject(id, t, n)
  173. {
  174.   SoSeparator* shipSep = new SoSeparator;
  175.  
  176.   SoMaterial* shipMat = new SoMaterial;
  177.   shipSep->addChild(shipMat);
  178.   shipMat->ambientColor.setValue(teamColor(t, 0.3));
  179.   shipMat->diffuseColor.setValue(teamColor(t, 1.0));
  180.   shipMat->specularColor.setValue(1.0, 1.0, 1.0);
  181.   shipMat->shininess = 0.4;
  182.  
  183.   SoShapeHints* shipHints = new SoShapeHints;
  184.   shipSep->addChild(shipHints);
  185.   shipHints->hints = SoShapeHints::SOLID | SoShapeHints::ORDERED |
  186.                         SoShapeHints::CONVEX;
  187.   shipHints->creaseAngle = 0.0;
  188.  
  189.   SoCoordinate3* shipCoord = new SoCoordinate3;
  190.   shipSep->addChild(shipCoord);
  191.   shipCoord->point.setValues(0, NUMCOORDS, shipGeometry);
  192.  
  193.   SoFaceSet* shipGeom = new SoFaceSet;
  194.   shipSep->addChild(shipGeom);
  195.   shipGeom->startIndex = 0;
  196.   shipGeom->numVertices.setValues(0, NUMEDGES, shipGeometryEdges);
  197.  
  198.   SoMaterial* engineMat = new SoMaterial;
  199.   shipSep->addChild(engineMat);
  200.   engineMat->ambientColor.setValue(0.1, 0.1, 0.1);
  201.   engineMat->diffuseColor.setValue(0.25, 0.25, 0.25);
  202.  
  203.   SoTranslation* enginePos1 = new SoTranslation;
  204.   shipSep->addChild(enginePos1);
  205.   enginePos1->translation.setValue(-9.0, 0.0, 14.0);
  206.  
  207.   SoRotation* engineRotate = new SoRotation;
  208.   shipSep->addChild(engineRotate);
  209.   engineRotate->rotation.setValue(SbRotation(SbVec3f(0.0, 1.0, 0.0),
  210.                         SbVec3f(0.0, 0.0, -1.0)));
  211.  
  212.   SoCone* engine = new SoCone;
  213.   shipSep->addChild(engine);
  214.   engine->parts = SoCone::SIDES;
  215.   engine->height = 4.0;
  216.   engine->bottomRadius = 6.0;
  217.  
  218.   SoTranslation* enginePos2 = new SoTranslation;
  219.   shipSep->addChild(enginePos2);
  220.   enginePos2->translation.setValue(18.0, 0.0, 0.0);
  221.  
  222.   engine = new SoCone;
  223.   shipSep->addChild(engine);
  224.   engine->parts = SoCone::SIDES;
  225.   engine->height = 4.0;
  226.   engine->bottomRadius = 6.0;
  227.  
  228.  
  229.   SoSeparator* shipChangeSep = new SoSeparator;
  230.   engineMat = new SoMaterial;
  231.   shipChangeSep->addChild(engineMat);
  232.   engineMat->ambientColor.setValue(0.0, 0.0, 0.0);
  233.   engineMat->diffuseColor.setValue(0.0, 0.0, 0.0);
  234.   engineMat->specularColor.setValue(0.0, 0.0, 0.0);
  235.   engineMat->emissiveColor.setValue(0.0, 1.0, 1.0);
  236.   engineMat->shininess = 0.0;
  237.   engineMat->transparency = 0.5;
  238.   enginePos1 = new SoTranslation;
  239.   shipChangeSep->addChild(enginePos1);
  240.   enginePos1->translation.setValue(-9, 0.0, 15.0);
  241.   shipChangeSep->addChild(engineRotate);
  242.  
  243.   rightEngine = new SoCone;
  244.   shipChangeSep->addChild(rightEngine);
  245.   rightEngine->parts = SoCone::SIDES;
  246.   rightEngine->height = 2.0;
  247.   rightEngine->bottomRadius = 3.0;
  248.  
  249.   shipChangeSep->addChild(enginePos2);
  250.  
  251.   leftEngine = new SoCone;
  252.   shipChangeSep->addChild(leftEngine);
  253.   leftEngine->parts = SoCone::SIDES;
  254.   leftEngine->height = 2.0;
  255.   leftEngine->bottomRadius = 3.0;
  256.  
  257.   init(shipSep, shipChangeSep, SbVec3f(0.0, -5.5, -19.0),
  258.                 SbVec3f(0.0, 10.0 + 1.75 * FLAGSIZE, 10.0),
  259.                 SbVec3f(0.0, 0.0, -15.0));
  260. }
  261.  
  262. RegularShip::~RegularShip()
  263. {
  264. }
  265.  
  266. ShipClass        RegularShip::shipClass() const
  267. {
  268.   return ShipClassRegular;
  269. }
  270.  
  271. float            RegularShip::mass() const
  272. {
  273.   return 50000.0;                // kg
  274. }
  275.  
  276. float            RegularShip::angularAccel() const
  277. {
  278.   return M_PI/3.0;                // rad/s/s
  279. }
  280.  
  281. float            RegularShip::engineMaxForce() const
  282. {
  283.   return 100.0 * 50000.0;            // N
  284. }
  285.  
  286. float            RegularShip::engineResponse() const
  287. {
  288.   return 0.6;
  289. }
  290.  
  291. float            RegularShip::fuelRate() const
  292. {
  293.   return 0.01;
  294. }
  295.  
  296. float            RegularShip::shieldMaximum() const
  297. {
  298.   return 100000.0;                // J
  299. }
  300.  
  301. float            RegularShip::shieldRecovery() const
  302. {
  303.   return 0.0;                    // J/s
  304. }
  305.  
  306. int            RegularShip::maxMissiles() const
  307. {
  308.   return 20;
  309. }
  310.  
  311. float            RegularShip::missileEnergy() const
  312. {
  313.   return 35000.0;                // J
  314. }
  315.  
  316. float            RegularShip::laserPower() const
  317. {
  318.   return 30000.0;                // J/s
  319. }
  320.  
  321. void            RegularShip::newEngineOutput()
  322. {
  323.   float e = 3.0 + 12.0 * engineOutput();
  324.   if (e < 3.0) e = 1.0;
  325.   rightEngine->height = 0.67 * e;
  326.   rightEngine->bottomRadius = e;
  327.   leftEngine->height = 0.67 * e;
  328.   leftEngine->bottomRadius = e;
  329. }
  330.  
  331. SbVec3f            RegularShip::missileSource(int s) const
  332. {
  333.   switch (s) {
  334.     case 0: return SbVec3f(-8.0, -5.0, -5.0);
  335.     case 1: return SbVec3f(-8.0, 5.0, -5.0);
  336.     case 2: return SbVec3f(8.0, 5.0, -5.0);
  337.     case 3: return SbVec3f(8.0, -5.0, -5.0);
  338.   }
  339.   return SbVec3f(0.0, 0.0, 0.0);
  340. }
  341.  
  342. int            RegularShip::missileSilos() const
  343. {
  344.   return 4;
  345. }
  346.